<?php
require_once ("../src/db/connectdatabase.php");

function getBankLoan($idloan) {
	$con = new ConnectDB();
	$tbl = "banksloan";
	$fn = array('bankloan_id', 'loan_id', 'dac_tinh_loan', 'object_dk_loan', 'thu_tuc_loan', 'bankid', 'bankname', 'banklogo', 'datecreate');
	$fcon = array('loan_id' => $idloan, 'isavalible' => true, 'bankuse' => true);
	$flike = array();
	return $con -> getvalueall($tbl,$fn,$fcon,$flike,'datecreate');
}

function int_to_date($int)
{
    $time  = date("d/m/Y", $int);
    return $time;
}

if(isset($_GET['as'])) {
	$check = true;
	$idloan = $_GET['as'];
	if($idloan == "vay_ca_nhan") {
		$vayname = "Vay Cá Nhân";
	} else if($idloan == "vay_tra_gop") {
		$vayname = "Vay Trả Góp";
	} else if($idloan == "vay_the_chap") {
		$vayname = "Vay Thế Chấp";
	} else {
		$check = false;
	}
	
	if($check) {
		$arrbankloans = getBankLoan($idloan);
		?>
<style>
.listbanksviewcontent table {
	width: 850px;
	max-width: 850px;
}

table td {
	margin-top: 2px;
	border: 1px solid;
	border-radius: 2px 2px 2px 2px;
}

table td img {
	cursor: pointer;
}

.title {
	text-align: center;
	background-color: #0088cc;
	min-height: 40px;
	-moz-border-radius: 8px 8px 0px 0px;
	-webkit-border-radius: 8px 8px 0px 0px;
	border-radius: 8px 8px 0px 0px;
	color: #FFF;
}

.stylenamebank {
	padding-left: 5px;
	padding-right: 5px;
	width: 350px;
	max-width: 350px;
}

.stylelogobank {
	width: 100px;
	text-align: center;
	max-width: 100px;
}

.styleacctionbank {
	width: 150px;
	text-align: center;
	max-width: 150px;
}

.styledatecreatebank {
	width: 100px;
	max-width: 100px;
	text-align: center;
}

.nameformbank {
	background: url(../images/bg-login.png);
	-moz-border-radius: 2px 2px 2px 2px;
	-webkit-border-radius: 2px 2px 2px 2px;
	border-radius: 2px 2px 2px 2px;
}

table tr:hover td {
	background: #FFC;
}

.showbanklistdeletedclick {
	color: #FFF;
	font-weight:bold;
	padding: 5px;background:#999; 
	-moz-border-radius: 5px 5px 5px 5px; 
	-webkit-border-radius: 5px 5px 5px 5px; 
	border-radius: 5px 5px 5px 5px; 
	cursor: pointer;
}

.reveal-modal-bg { 
	position: fixed; 
	height: 100%;
	width: 100%;
	background: #000;
	background: rgba(0,0,0,.8);
	z-index: 100;
	display: none;
	top: 0;
	left: 0; 
}
		
#showlistbankdeletedlightbox {
	display: none;
	top: 0px; 
	left: 50%;
	margin-left: -400px;
	width: 800px;
	background: #eee url(modal-gloss.png) no-repeat -200px -80px;
	position: absolute;
	z-index: 101;
	padding: 0px 0px 0px;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow: 0 0 10px rgba(0,0,0,.4);
	-webkit-box-shadow: 0 0 10px rgba(0,0,0,.4);
	-box-shadow: 0 0 10px rgba(0,0,0,.4);
}

#showlistbankdeletedlightbox .close-reveal-modal {
	font-size: 22px;
	line-height: .5;
	position: absolute;
	top: 8px;
	right: 11px;
	color: #aaa;
	text-shadow: 0 -1px 1px rbga(0,0,0,.6);
	font-weight: bold;
	cursor: pointer;
} 
.reveal-modal-title {
    background: url('../images/box-title-blue.jpg') repeat-x;
    height: 50px;
    text-align: center;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
}

.reveal-modal-title h1 {
    color: white;
}

.reveal-modal-main {
    padding: 20px;
	min-height: 400px;
	max-height: 400px;
	overflow-y: scroll;
}

.stylestt {
	width: 70px;
}
</style>
<h3>Danh Sách Các Ngân Hàng Cho <?php echo($vayname) ?></h3>
<div class="listbanksviewcontent">
	<table>
    	<tr>
        	<th class="stylestt title">STT</th>
        	<th class="stylenamebank title">Ngân Hàng</th>
            <th class="stylelogobank title">Logo</th>
            <th class="styledatecreatebank title">Ngày Cập Nhật</th>
            <th class="styleacctionbank title">Chức Năng</th>
        </tr>
        <?php
		if(count($arrbankloans) > 0) {
			for($i=0; $i<count($arrbankloans); $i++) {
				?>
        <tr>
        	<td class="stylestt nameformbank" align="center"><?php echo($i + 1) ?></td>
        	<td class="stylenamebank nameformbank"><?php echo($arrbankloans[$i][6]) ?></td>
            <td class="stylelogobank nameformbank"><img width="90px;" height="25px" src="../<?php echo($arrbankloans[$i][7]) ?>" /></td>
            <td class="styledatecreatebank nameformbank"><?php echo(int_to_date($arrbankloans[$i][8])) ?></td>
            <td class="styleacctionbank nameformbank"><img idbankloan="<?php echo($arrbankloans[$i][0]) ?>" width="20px;" class="class-detailbankloan-link" src="../images/icon-detail.gif" title="Xem Chi Tiết <?php echo($arrbankloans[$i][6]) ?>" />&nbsp; | &nbsp;<img idbankloan="<?php echo($arrbankloans[$i][0]) ?>" class="class-deletebankloan-link" src="../images/icon-delete.gif" width="20px;" title="Xóa" /></td>
        </tr>
                <?php
			}
		} else {
		?>
        <tr><th colspan="4">Chưa có danh sách ngân hàng nào cho <?php echo($vayname) ?></th></tr>
        <?php	
		}
		?>
    </table>
</div>
<div><a href="admin.php?content=quanlivay&&as=<?php echo($idloan) ?>&&adrt=addbankloan"><img src="../images/icon-add.jpg" title="Thêm Ngân Hàng Cho Vay" />Thêm Ngân Hàng Cho <?php echo($vayname) ?></a></div>

<script>
	$(document).on('click', '.class-detailbankloan-link', function(e) {
		elem = $(this)
		var idbloan = elem.attr('idbankloan');
		window.location= 'admin.php?content=quanlivay&&as=<?php echo($idloan) ?>&&adrt=detailbankloan&&id=' + idbloan;
	});
	
	$(document).on('click', '.class-deletebankloan-link', function() {
		elem = $(this)
		var idbloan = elem.attr('idbankloan');
		if(confirm("Bạn có muốn xóa?")) {
			$.ajax({
				url: "../src/ajax/ajaxbankloan.php",
				type: "post",
				data: {act:'del', idre: idbloan},
				dataType:"json",
				success: function(data) {
					if(data == true) {
						elem.parent().parent().fadeOut(300, function(){elem.parent().parent().remove();});
					} else {
						alert("Cập nhật dữ liệu không thành công");
					}
				}
			});
		}
	});
</script>
        <?php
	}
}
?>
